package com.hele.sts.action.admin;

import java.util.List;
import java.util.Map;

import com.hele.sts.dao.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.hele.sts.webwork.PageAction;
import com.opensymphony.xwork2.ActionContext;
import org.springframework.beans.factory.annotation.Autowired;

public class EntListAction extends PageAction {

	private static final String ACTION_MOVE_LIST = "move_list";

	String action;
	String errorInfo;

	String qymc;
	String nbxh;
	String zch;
	String djjg;
	String gxdw;
	String qyzt;

	boolean noList;

	List djjgList;
	List gxdwList;
	
	List qyhznrList;
	
	Datjxx tjxx;
	
	String startDate;
	String endDate;

	//xuning add for move 20190404


	static Logger logger = LoggerFactory.getLogger(EntListAction.class);

	@Autowired
	private XtLogDao xtLogDao;
	
	public EntListAction(){
	    this.noList = false;
	}

	@Override
	public String execute() throws Exception {
		ActionContext ctx = ActionContext.getContext();
		Map session = ctx.getSession();
		String loginName = (String) session.get("AdminUser.loginName");
		if ((loginName == null) || (loginName.length() < 1)) {
			setErrorInfo("没有登录");
			return "error";
		}
		if ((this.action == null) || ("list".equalsIgnoreCase(this.action) ||(ACTION_MOVE_LIST.equalsIgnoreCase(this.action)))) {
			return super.execute();
		}

		return "none";
	}

	@Override
	public String getHref() {
		String href = "";
		// if ((this.userId != null) && (this.userId.length() > 0)) {
		// href = href + "&userId=" + this.userId;
		// }
		if ((this.qymc != null) && (this.qymc.length() > 0)) {
			href = href + "&qymc=" + this.qymc;
		}
		if ((this.nbxh != null) && (this.nbxh.length() > 0)) {
			href = href + "&nbxh=" + this.nbxh;
		}
		if ((this.zch != null) && (this.zch.length() > 0)) {
			href = href + "&zch=" + this.zch;
		}
		return href;
	}

	@Override
	public int count() {
		if (this.noList) {
			return 0;
		}

		ActionContext ctx = ActionContext.getContext();
		Map session = ctx.getSession();
		String djjg = (String) session.get("AdminUser.djjg");
		if(this.djjg==null||"".equals(djjg)){
			this.djjg = djjg.endsWith("00") ? djjg.substring(0, 4) : djjg;
		}
		
		this.gxdw = (String) session.get("AdminUser.gxdw");
		if (gxdw.endsWith("00")) {
			this.gxdw = gxdw.substring(0, gxdw.length() - 2);
		}
		if (gxdw.endsWith("00")) {
			this.gxdw = gxdw.substring(0, gxdw.length() - 2);
		}
		if ("2".equals(this.qyzt)) {
			return QyhznrDao.countBfForImage(this.qymc, this.nbxh, this.zch, this.djjg, this.gxdw,this.startDate,this.endDate);
		} else {
			return QyhznrDao.countForImage(this.qymc, this.nbxh, this.zch, this.djjg, this.gxdw,this.startDate,this.endDate);
		}
	}

	@Override
	public String list() {
		if (!this.noList) {
			if ("2".equals(this.qyzt)) {
				this.qyhznrList = QyhznrDao.loadbfForImage(this.qymc, this.nbxh, this.zch, this.djjg, this.gxdw,this.startDate,this.endDate, getPageNo(),
						getPageSize());
			} else {
				this.qyhznrList = QyhznrDao.loadForImage(this.qymc, this.nbxh, this.zch, this.djjg, this.gxdw,this.startDate,this.endDate, getPageNo(),
						getPageSize());
				
			}
		}
		djjgList = DjjgDao.loadDjjg();
		if(!ACTION_MOVE_LIST.equals(action)){
			tjxx = QyjnmlbDao.getDatjxx(djjg,startDate,endDate);
			return "list";
		}else{
			return "listForMove";
		}


	}

	public String getErrorInfo() {
		return this.errorInfo;
	}

	public void setErrorInfo(String errorInfo) {
		this.errorInfo = errorInfo;
	}

	public String getAction() {
		return this.action;
	}

	public void setAction(String action) {
		this.action = action;
	}

	/**
	 * @return the qymc
	 */
	public String getQymc() {
		return qymc;
	}

	/**
	 * @param qymc the qymc to set
	 */
	public void setQymc(String qymc) {
		this.qymc = qymc;
	}

	/**
	 * @return the nbxh
	 */
	public String getNbxh() {
		return nbxh;
	}

	/**
	 * @param nbxh the nbxh to set
	 */
	public void setNbxh(String nbxh) {
		this.nbxh = nbxh;
	}

	/**
	 * @return the zch
	 */
	public String getZch() {
		return zch;
	}

	/**
	 * @param zch the zch to set
	 */
	public void setZch(String zch) {
		this.zch = zch;
	}

	/**
	 * @return the djjg
	 */
	public String getDjjg() {
		return djjg;
	}

	/**
	 * @param djjg the djjg to set
	 */
	public void setDjjg(String djjg) {
		this.djjg = djjg;
	}

	/**
	 * @return the gxdw
	 */
	public String getGxdw() {
		return gxdw;
	}

	/**
	 * @param gxdw the gxdw to set
	 */
	public void setGxdw(String gxdw) {
		this.gxdw = gxdw;
	}

	/**
	 * @return the qyzt
	 */
	public String getQyzt() {
		return qyzt;
	}

	/**
	 * @param qyzt the qyzt to set
	 */
	public void setQyzt(String qyzt) {
		this.qyzt = qyzt;
	}

	/**
	 * @return the noList
	 */
	public boolean isNoList() {
		return noList;
	}

	/**
	 * @param noList the noList to set
	 */
	public void setNoList(boolean noList) {
		this.noList = noList;
	}

	/**
	 * @return the qyhznrList
	 */
	public List getQyhznrList() {
		return qyhznrList;
	}

	/**
	 * @param qyhznrList the qyhznrList to set
	 */
	public void setQyhznrList(List qyhznrList) {
		this.qyhznrList = qyhznrList;
	}

	/**
	 * @return the djjgList
	 */
	public List getDjjgList() {
		return djjgList;
	}

	/**
	 * @param djjgList the djjgList to set
	 */
	public void setDjjgList(List djjgList) {
		this.djjgList = djjgList;
	}

	/**
	 * @return the tjxx
	 */
	public Datjxx getTjxx() {
		return tjxx;
	}

	/**
	 * @param tjxx the tjxx to set
	 */
	public void setTjxx(Datjxx tjxx) {
		this.tjxx = tjxx;
	}

	/**
	 * @return the startDate
	 */
	public String getStartDate() {
		return startDate;
	}

	/**
	 * @param startDate the startDate to set
	 */
	public void setStartDate(String startDate) {
		this.startDate = startDate;
	}

	/**
	 * @return the endDate
	 */
	public String getEndDate() {
		return endDate;
	}

	/**
	 * @param endDate the endDate to set
	 */
	public void setEndDate(String endDate) {
		this.endDate = endDate;
	}
	
	
}
